package com.itheima.mapper;

import com.itheima.pojo.Dept;
import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

/**
 * 员工管理Mapper
 */
@Mapper
public interface EmpMapper {
    /**
     * 查询总记录数
     */
    //@Select("select count(*) from emp")
    //public Long count();


    /**
     * 获取分页查询的数据列表
     */
    //@Select("select * from emp limit #{start},#{PageSize}")
    //public List<Emp> page(@Param("start") Integer start, @Param("PageSize") Integer PageSize);

    /**
     * 员工信息查询
     */
//    @Select("select * from emp")
    public List<Emp> list(@Param("name") String name, @Param("gender") Short gender, @Param("begin") LocalDate begin, @Param("end") LocalDate end);


    /**
     * 批量删除员工
     *
     * @param ids
     */
    void deleteByIds(@Param("ids") List<Integer> ids);


    /**
     * 新增员工
     *
     * @param emp
     */
    @Insert("insert into emp (image, username, name, gender, job, entrydate, dept_id, create_time, update_time)" +
            "values (#{image}, #{username}, #{name}, #{gender}, #{job}, #{entrydate}, #{deptId}, #{createTime}, #{updateTime});")
    void insert(Emp emp);

    /**
     * 根据id查询员工信息
     *
     * @param id
     * @return
     */

    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time " +
            "from emp where id=#{id}")
    Emp selectById(Integer id);


    /**
     * 修改员工信息
     * @param emp
     */
    void update(Emp emp);


    /**
     * 登录
     * @param emp
     * @return
     */

    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time " +
            "from emp " +
            "where username=#{username} and password=#{password}")
    Emp getByUsernameAndPassword(Emp emp);


    /**
     * 删除部门后 该部门下的员工也应该删除
     * @param deptId
     */
    @Delete("delete from emp where dept_id=#{deptId}")
    void deledeptById(Integer deptId);
}
